<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入Vue -->
    <script type="text/javascript" src="../js/vue.js"></script>

</head>
<body>
    <!-- 准备好一个容器 -->
    <div id="root">
        <h2>当前的n值是：{{n}}</h2>
        <button @click="add">点我n+1</button>
        <button @click="bye">点我销毁vm</button>
    </div>

</body>
    <script type="text/javascript">
        const vm = new Vue({
            el:'#root',
            data:{
                n:1
            },
            methods: {
                add(){
                    console.log('add')
                    this.n+=1;
                },
                bye(){
                    console.log('bye')
                    this.$destroy()
                }
            },

            watch:{
                n(){
                    console.log('n值发生了改变')
                }
            },

            beforeCreate() {
                console.log('beforeCreate');
                // console.log(this);
                // debugger;
            },
            created() {
                console.log('created');
                // console.log(this);
                // debugger;
            },
            beforeMount() {
                console.log('beforeMount');
                // console.log(this);
                // debugger;  
                //无效
                // document.querySelector('h2').innerHTML = 'haha'
            },
            mounted() {
                console.log('mounted');
                // console.log(this);
                // debugger;
                //有效，但尽可能避免
                // document.querySelector('h2').innerHTML = 'haha'
            },
            beforeUpdate() {
                console.log('beforeUpdate');
                // console.log(this.n);
                // debugger;
            },

            updated() {
                console.log('updated')
                // console.log(this.n);
                // debugger;
            },

            beforeDestroy() {
                console.log('beforeDestroy');
                console.log(this.n)
                
            },

            destroyed() {
                console.log('destroyed')
            },
        })       

    </script>

</html>